import {request,RequestConfig,HttpRequestMethod,LengyuHttpResponse,PageRequestParam,download,upload}  from '../utils/request'

export  interface Vote {
  id?: string
  userId?: string
  title:string
  description?:string
  maxChoices:number
  endTime:string
  optionsList?:VoteOption[]
  recordsList?:VoteRecord[]
}
export interface VoteOption{
  id?: string
  content?:string
  voteCount?:number
  percentage?:number
  votedAvatars?:Array<string>
}
export  interface VoteRecord{
  id?:string
  userId?:string
  voteOptionId?:string
  voteId?:string
  vxNickName?:string
  vxAvatar?:string
}

// 将微信用户信息保存到数据库
export function save(vote:Vote): Promise<LengyuHttpResponse> {
  vote.userId=wx.getStorageSync('userId')
  let requestConfig:RequestConfig={
    url:'/votes/save',
    method:HttpRequestMethod.POST,
    data:vote,
    token:true,
  }
  return request(requestConfig);
}


export function page(param:PageRequestParam): Promise<LengyuHttpResponse> {
  let requestConfig:RequestConfig={
    url:'/votes/page',
    method:HttpRequestMethod.POST,
    data:param,
    token:true,
  }
  return request(requestConfig);
}
export function detail(id:string): Promise<LengyuHttpResponse> {
  let requestConfig:RequestConfig={
    url:'/votes/detail?id='+id,
    method:HttpRequestMethod.GET,
    token:true,
  }
  return request(requestConfig);
}

/**
 * 
 * @param param 
 */
export function vote(voteId:string,optionId:string): Promise<LengyuHttpResponse> {
  let param={
    voteId:voteId,
    optionId:optionId
  }
  let requestConfig:RequestConfig={
    url:'/votes/vote',
    method:HttpRequestMethod.POST,
    data:param,
    token:true,
  }
  return request(requestConfig);
}

// export function takePageCar(param:PageRequestParam): Promise<LengyuHttpResponse> {
//   let requestConfig:RequestConfig={
//     url:'/car/takePageCar',
//     method:HttpRequestMethod.POST,
//     data:param,
//     token:true,
//   }
//   return request(requestConfig);
// }